<template>
  <div>
    <div>
      <el-input v-model="projectDocName" placeholder="请输入文档标题" :disabled="true"></el-input>
    </div>
    <div id="markdown">
      <mavon-editor v-model="initContent"
                    :editable="false"
                    :subfield = "false"
                    :defaultOpen = "'preview'"
                    :toolbarsFlag = "false"
                    :scrollStyle="true"
                    :ishljs = "true"
                    />
    </div>
  </div>
</template>


<script>

  import Vue from 'vue'
  import mavonEditor from 'mavon-editor'
  import 'mavon-editor/dist/css/index.css'
  import api from "@/assets/js/project/project_doc_view.js";
  import common from "@/assets/js/common/common.js";

  Vue.use(mavonEditor);

  import axios from 'axios'
  import qs from "qs";


  export default {
    //数据类型
    data() {
      return {
        initContent: "",
        projectDocId: null,
        projectInfoId: null,
        projectDocName: null,
        markdownStatus: true
      }
    },
    //在components中引入子组件
    components: {},
    //初始化加载
    mounted: function () {
      //获取文档主键
      if (this.$route.params.projectDocId) {
        this.projectDocId = this.$route.params.projectDocId
      } else if (localStorage.getItem("projectDocId")) {
        this.projectDocId = localStorage.getItem("projectDocId")
      }
      //获取项目主键
      if (this.$route.params.projectInfoId) {
        this.projectInfoId = this.$route.params.projectInfoId
      } else if (localStorage.getItem("projectInfoId")) {
        this.projectInfoId = localStorage.getItem("projectInfoId")
      } else {
        common.message("无法获取项目信息", "warning");
      }
      //获取文档标题
      if (this.$route.params.projectDocName) {
        this.projectDocName = this.$route.params.projectDocName
      } else if (localStorage.getItem("projectDocName")) {
        this.projectDocName = localStorage.getItem("projectDocName")
      }

      if (this.projectDocId) {
        this.getProjectDocById({
          projectDocId: this.projectDocId
        });
      } else {
        this.initContent = "# 初始化【新增】";
        this.projectDocName = "";
      }
    },
    //具体js方法
    methods: {
      getProjectDocById(param) {
        api.getProjectDocById(param).then((res) => {
          console.log(res.data);
          this.initContent = res.data.markdownDoc;
        });
      },
      save(value, render) {
        console.log("value:", value);
        console.log("render:", render);
      }
    }
  }
</script>


<style scoped>


</style>
